#ifndef __STARALIGN_H__
#define __STARALIGN_H__

#define	MIN_STAR_COUNT 15	
#define False 0
#define True  1

#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <math.h>

#include "pixel_lib.h" 

using namespace cv;

typedef struct _triangleFeature {
	imgObject		*obj[3];
	float			angle[3];
	float			metric;
	char 			objMatch[3];
	unsigned int	index[3];
} triangleFeature;

typedef struct _possibleMatch {
	triangleFeature *tri1;
	triangleFeature *tri2;
} possibleMatch;

typedef struct _starMatch {
	char file[2048];
	char filePrimary[2048];
//	triangleFeature	*trianglePrimary;
//	triangleFeature	*triangleMatch;
	float scale;
	float rotate;
	int deltaX;
	int deltaY;	
} starMatch;

int StarDetection(const Mat& imgSrc);
unsigned int TriangulateFeatures(imgObject*, unsigned int, triangleFeature*); 
int FindAndClassifyStars(const Mat&, imgObject **, unsigned int *);
float UnitDotProduct(float,float,float,float);
int	CrossProduct(float , float , float , float);
float	Mag(float a, float b);
float FindAngle(float , float, float, float, float, float); 
char MatchObjects(triangleFeature *, triangleFeature *, unsigned int, unsigned int, float, float, float, unsigned int *, unsigned int *, possibleMatch *, unsigned int *);
char CheckMassOrder(triangleFeature, triangleFeature); 
void LogMatchSituation(const char* , const char*, starMatch*, starMatch, bool); 
void LogStarSituation(const char*, starMatch *, int);
int alignImages(starMatch *, const Mat&, const Mat&, unsigned int&, float , float , float, unsigned int);
char AuditMatches(possibleMatch*, unsigned int, starMatch*);
char TransformMatch(triangleFeature *, triangleFeature *, float *, float *, float *, float *);
double factorial(unsigned int);
double nchoosek(unsigned int, unsigned int);
#endif
